<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">  
<html>  
<head>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
        <title>MINI-TextField</title>  
         <script src="https://asmstatic.jsonmedia.com/js/boot.js" type="text/javascript"></script>
        <script type="text/javascript" src="../../dialogs/internal.js"></script>  
        <script type="text/javascript" src="../js/control.js"></script>    
</head>  
<body>  
    <form id="miniForm">  
        <table class="table-detail" cellspacing="1" cellpadding="0">  
            <caption>文本框基础属性</caption>  
            <tr>  
                <th>名称*</th>  
                <td>  
                    <input class="mini-textbox" name="name" id="name" required="true" vtype="maxLength:80" style="width:90%"/>  
                </td>  
                <th>必填*</th>  
                <td>  
                    <input class="mini-checkbox" name="isRequired" id="isRequired"/>是  
                </td>  
            </tr>  
        </table>  
    </form>  
    <script type="text/javascript">  
      
        function createElement(type, name){       
            var element = null;       
            try {          
                element = document.createElement('<'+type+' name="'+name+'">');       
            } catch (e) {}     
            if(element==null) {       
                element = document.createElement(type);       
                element.name = name;       
            }   
            return element;       
        }  
          
        mini.parse();  
        var form=new mini.Form('miniForm');  
        //编辑的控件的值  
        var oNode = null,  
        thePlugins = 'mini-textbox';  
          
        window.onload = function() {  
            //若控件已经存在，则设置回调其值  
            if( UE.plugins[thePlugins].editdom ){  
                //  
                oNode = UE.plugins[thePlugins].editdom;  
                //获得字段名称  
                  
                var name = oNode.getAttribute('name');  
                var isRequried=oNode.getAttribute("required");  
                mini.get('name').setValue(name);  
                mini.get('isRequired').setValue(isRequried);  
            }  
        }  
        //取消按钮  
        dialog.oncancel = function () {  
            if( UE.plugins[thePlugins].editdom ) {  
                delete UE.plugins[thePlugins].editdom;  
            }  
        };  
        //确认  
        dialog.onok = function (){  
            form.validate();  
            if (form.isValid() == false) {  
                return false;  
            }  
            var name=mini.get('name').getValue();  
            var isRequired=mini.get('isRequired').getValue();  
              
            //控件尚未存在，则创建新的控件，否则进行更新  
            if( !oNode ) {  
                try {  
                    oNode = createElement('input',name);
                    oNode.setAttribute('class','mini-textbox');  
                    oNode.setAttribute('required',isRequired);  
                    //需要设置该属性，否则没有办法其编辑及删除的弹出菜单  
                    oNode.setAttribute('plugins',thePlugins);  
                    editor.execCommand('insertHtml',oNode.outerHTML);  
                } catch (e) {  
                    try {  
                        editor.execCommand('error');  
                    } catch ( e ) {  
                        alert('控件异常，请联系技术支持');  
                    }  
                    return false;  
                }  
            } else {//已经存在，则更新属性则可  
                oNode.setAttribute('title', name);  
                oNode.setAttribute('required', isRequired);  
                delete UE.plugins[thePlugins].editdom;  
            }  
        };  
          
    </script>  
</body>  
</html>  